<!--
- Author:   .
- Date:    2017/7/17 0017.
- File:    step1.
-->
<template>
  <div class="p20 apply_box bg_fff">
    <p>退款原因 </p>
    <div class="apply_sel"><i class="iconfont icon-downdot2"></i><select v-model="reasonIdSelect">
      <option value="" selected>请选择退款原因</option>
      <option v-for="item in refundMoneyReasonList" v-bind:value="item.reason_id">{{item.reason_info}}</option>
    </select></div>
    <div class="apply_txt">
      <p>本次退款金额合计：<span class="cr_f60202">￥{{orderInfo.order_info.order_amount}}</span></p>
      <div class=" f26">其中 在线退款:￥{{orderInfo.order_info.pay_amount || 0}}&nbsp;积分退还:{{parseInt(orderInfo.order_info.integral_amount || 0)}}&nbsp;余额退还:￥{{orderInfo.order_info.balance_amount || 0}}</div>
      <div class="cr_41a536 pt10">退款成功后的金额将原路返回支付账户<span v-if="parseInt(orderInfo.order_info.get_integral) > 0">，同时本次购买赠送的{{parseInt(orderInfo.order_info.get_integral)}}积分将被扣除。</span></div>

    </div>
    <p class="pt20">退款说明 </p>
    <div class="apply_sel"><textarea placeholder="最多200字" v-model="remark"></textarea></div>
    <div class="apply_sel2">
      <button @click="addRefund">提交申请</button>
    </div>
    <back-nav></back-nav>
  </div>
</template>

<script>
  import {mapModules, mapRules} from 'vuet'

  export default{
    mixins: [
      mapModules({refundMoneyReasonList: 'refundMoneyReasonList'}),
      mapRules({once: 'refundMoneyReasonList'})
    ],
    data() {
      return {
        goodsId: this.$route.params.goodsId,
        orderId: this.$route.params.orderId,
        reasonIdSelect: '',
        remark: '',
        orderInfo: {order_info: {}}
      }
    },
    components: {},
    watch: {
      num: function (newValue) {
        if (newValue > 10) {
          this.num = 10
        }
      }
    },
    computed: {
      // 退款/退货扣除的积分
      integration: function () {
        if (this.orderInfo.order_info && this.orderInfo.order_info.pay_amount) {
          let moneyPayed = parseFloat(this.orderInfo.order_info.pay_amount)
          return Math.floor(moneyPayed * 0.2)
        }
        return 0
      }
    },
    created() {
      this.getOrderInfo(this.orderId)
    },
    methods: {
      getOrderInfo(id) {
        this.$request.getOrderInfo(id).then(data => {
          this.orderInfo = data
        })
      },
      addRefund() {
        if (this.reasonIdSelect == '') {
          this.$toast('请选择原因')
          return
        }
        let param = {
          buyer_message: this.remark,
          goods_id: this.goodsId,
          order_id: this.orderId,
          reason_info: this.reasonIdSelect,
          refund_type: this.$dictionary.refundType.money
        }
        this.$indicator.open('提交中...')
        this.$request.addRefund(param).then(data => {
          this.$toast('申请退款成功')
          this.$router.replace({name: 'refund-list'})
        }).catch(e => {
          this.$toast('申请退款失败：' + e.msg)
        }).finally(() => {
          this.$indicator.close()
        })
      }
    }
  }
</script>

<style>

</style>